/*
package com.netty.demo.server.netty.coder;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufUtil;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.IntStream;

*/
/**
 * netty服务解码器
 *
 * @author yxl 余秀良
 * @version 1.0
 * <p>date: 2019年09月07日  下午10:41 </p>
 * <p>address: 四川成都 </p>
 *//*

@Component
@Slf4j
public class ServerMessageDecoder extends ByteToMessageDecoder {
    */
/**
 * Decode the from one {@link ByteBuf} to an other. This method will be called till either the input
 * {@link ByteBuf} has nothing to read when return from this method or till nothing was read from the input
 * {@link ByteBuf}.
 *
 * @param ctx the {@link ChannelHandlerContext} which this {@link ByteToMessageDecoder} belongs to
 * @param in  the {@link ByteBuf} from which to read data
 * @param out the {@link List} to which decoded messages should be added
 * @throws Exception is thrown if an error occurs
 *//*

    @Override
    protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
        */
/*
 * 传递的数据都是在ByteBuf 这个参数中
 * java 数据类型对应字节
 *byte     1字节
 * short    2字节
 * int      4字节
 *long     8字节
 *char     2字节
 * float    4字节
 * double   8字节
 * boolean  false/true (理论上占用1bit,1/8字节，实际处理按1byte处理)
 * ByteBuf  的read 操作是会改变索引
 * 读取和规定格式不一样,会读串数据.
 *//*

        Map<String, Object> dataMap = new HashMap<>(16);
        // 读取原始数据串 不会改变ByteBuf 索引
        String originalData = ByteBufUtil.hexDump(in);
        dataMap.put("originalData", originalData);
        */
/*按照规定的数据协议读取数据
        如果在规定的协议中，有大端字节和小端字节的问题
         netty 把  in.readShort() 改为 readShortLE()
        Byte   Long  读取方式同上   改为带LE的方法即可*//*

        dataMap.put("Length", in.readShort());
        dataMap.put("Header1", in.readByte());
        dataMap.put("data", in.readLong());
        //遇到 6个 字节 的规定,每次读取一个字节  拼接到StringBuffer 中
        StringBuffer sb = new StringBuffer();
        //Stream 表达式代替for 循环
        IntStream.range(0, 6).forEach(i -> {
            sb.append(in.readByte());
        });
        dataMap.put("checkCode", sb.toString());
        out.add(dataMap);
    }
}
*/
